<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="订单编码">
              <a-input placeholder="请输入订单编码" v-model="queryParam.orderNo"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="买家昵称">
              <a-input placeholder="请输入买家昵称" v-model="queryParam.nickname"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户手机号">
              <a-input placeholder="请输入用户手机号" v-model="queryParam.phone"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="收货人/电话">
                <a-input placeholder="请输入收货人/电话" v-model="queryParam.addressInfo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="支付方式">
                <j-dict-select-tag v-model="queryParam.payChannel" dictCode="pay_channel"  />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="开票类型">
                <a-select :default-value="null" v-model="queryParam.invoiceType" @change="searchQuery">
                  <a-select-option :value="null">
                    全部
                  </a-select-option>
                  <a-select-option :value="''">
                    不开票
                  </a-select-option>
                  <a-select-option :value="1">
                    个人发票
                  </a-select-option>
                  <a-select-option :value="2">
                    企业发票
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="创建时间">
                <a-range-picker format="YYYY-MM-DD" :placeholder="['开始时间', '结束时间']" @change="onDateChange" />
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px;">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-radio-group :default-value="null" v-model="queryParam.status" @change="searchQuery" button-style="solid">
        <a-radio-button :value="null">
          全部
        </a-radio-button>
        <a-radio-button :value="1">
          待付款
        </a-radio-button>
        <a-radio-button :value="2">
          待发货
        </a-radio-button>
        <a-radio-button :value="3">
          已发货
        </a-radio-button>
        <a-radio-button :value="4">
          待评价
        </a-radio-button>
        <a-radio-button :value="5">
          交易取消
        </a-radio-button>
        <a-radio-button :value="6">
          交易完成
        </a-radio-button>
      </a-radio-group>

    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="orderNo" :columns="columns" :dataSource="dataSource"
        :pagination="ipagination" :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap" @change="handleTableChange">

        <template slot="skuList" slot-scope="text, record">
          <div v-for="(item,index) in record.skuList" :key="index" :class="record.skuList.length==index+1?'':'b-b'">
            <div style="display:flex;">
              <div style="padding:4px;">
                <img style="width:40px;" :src="item.imgUrl">
              </div>
              <div style="flex:1;padding:4px;text-align:left;border-right:solid 1px #dddddd;min-height:62px;">
                <div style="width:120px;white-space: normal;word-break: break-all;word-wrap: break-word;color:#333333;line-height:18px;">
                  {{ item.spuName }}</div>
                <div style='margin-top: 5px;width:120px;white-space: normal;word-break: break-all;word-wrap: break-word;font-size:12px;'>
                  {{ item.skuName }}</div>
              </div>
              <div style="width:100px;text-align:left;padding:4px;min-height:62px;">
                <b>金额：</b>{{ item.skuPrice }}<br><b>数量：</b>{{ item.num }}件
              </div>
              <!-- <div style="width:60px;text-align:center;padding:4px;font-size:12px;">
                <span v-if="item.refundNo">退款中</span>
                <a v-else-if="record.status==2||record.status==3" @click="activeRefund(item)">可主动退款</a>
              </div> -->
            </div>
          </div>
        </template>
        <template slot="addressInfoObj" slot-scope="text, record">
          {{ record.nickname }}<br>{{ record.addressInfoObj.name }}<br>{{ record.addressInfoObj.tel }}
        </template>
        <template slot="teamNumInfo" slot-scope="text, record">
          {{ record.teamNum }}/{{ record.teamNum }}
        </template>

        <template slot="remindTimeSlot" slot-scope="text, record">
          <div v-if="record.remindTime" style="width:80px;white-space: normal;word-break: break-all;word-wrap: break-word;color:red;">
            {{record.remindTime + "提醒" }}
          </div>
          <div v-if="!record.remindTime" style="width:80px;">
            未提醒
          </div>
        </template>

        <template slot="payInfo" slot-scope="text, record">
          <div style="text-align:left;"><b>支付金额：</b>{{ record.amount }}</div>
          <div style="text-align:left;"><b>支付渠道：</b>{{ record.payChannel_dictText }}</div>
          <div style="text-align:left;"><b>发票信息：</b>{{ record.invoiceType == null ? "无发票" : record.invoiceType == 1 ? '个人发票' : '企业发票' }}</div>
        </template>
        <template slot="remarks" slot-scope="text, record">
          <div class="remarks">
            <div class="remarks-item"><b>买家留言：</b>{{ record.customerRemark }}</div>
            <div class="remarks-item"><b>平台备注：</b>{{ record.shopRemark }}</div>
            <!-- <div class="remarks-item"><b>平台备注：</b>{{ record.platformRemark }}</div> -->
          </div>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="55px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleInfo(record)">查看</a>

        </span>

      </a-table>
    </div>

  </a-card>
</template>

<script>
import { postAction } from '@/api/manage'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
import JDate from '@/components/jeecg/JDate.vue'

export default {
  name: 'omsOrderPtList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDictSelectTag,
    JDate
  },
  data () {
    return {
      actOrderNo: '',
      sRemark: false,
      shopRemark: '',
      description: '订单管理页面',
      active_refund_orderSkuId: '',
      active_refund_visible: false,
      active_refund_confirmLoading: false,
      active_refund_amount: 0,
      active_refund_reason: '',
      // 表头
      columns: [
        // {
        //   title: '订单编码',
        //   align: "center",
        //   dataIndex: 'orderNo'
        // },
        {
          title: '商品信息',
          align: "center",
          dataIndex: 'skuList',
          scopedSlots: { customRender: 'skuList' }
        },
        {
          title: '店铺',
          align: "center",
          dataIndex: 'shopName'
        },
        {
          title: '参与人数/目标人数',
          align: "center",
          dataIndex: 'teamNum',
          scopedSlots: { customRender: 'teamNumInfo' }
        },
        {
          title: '买家/收货人',
          align: "center",
          dataIndex: 'addressInfoObj',
          scopedSlots: { customRender: 'addressInfoObj' }
        },
        {
          title: '支付/发票',
          align: "center",
          dataIndex: 'amount',
          scopedSlots: { customRender: 'payInfo' }
        },
        {
          title: '下单时间',
          align: "center",
          dataIndex: 'createTime',
          sorter: true,
        },
        {
          title: '提醒发货',
          align: "center",
          dataIndex: 'remindTime',
          sorter: true,
          scopedSlots: { customRender: 'remindTimeSlot' }
        },
        {
          title: '订单状态',
          align: "center",
          dataIndex: 'status_dictText',
          sorter: true,
        },
        {
          title: '留言/备注',
          align: "center",
          dataIndex: 'customerRemark',
          scopedSlots: { customRender: 'remarks' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/mallPlus/omsOrder/ptList"
      },
      dictOptions: {},
    }
  },
  created () {

  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {

    initDictConfig () {
    },
    handleInfo (record) {
      this.$router.push({ path: '/order/mng/OmsOrderInfo', query: { id: record.orderNo, type: record.type, isCycle: 1 } })
    },

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
.b-b {
  border-bottom: solid 1px #dddddd;
  text-align: left;
}
.b-b:last-child {
  border-bottom: none;
  text-align: left;
}
.remarks {
  font-size: 11px;
  width: 150px;
  text-align: left;
  white-space: normal;
  word-break: break-all;
  word-wrap: break-word;
}
.remarks-item {
  background-color: #f4f4f4;
  padding: 5px;
  margin-bottom: 4px;
  border-radius: 4px;
}
</style>
